package com.mz.ozy.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.MallBean;
import com.mz.ozy.utils.glideUtils.GlideUtils;

import java.util.List;

/**
 * Created by administrator on 2018/11/21.
 */
public class MallCenterAdapter extends BaseQuickAdapter<MallBean.KtProductListBean, BaseViewHolder> {


    public MallCenterAdapter(@Nullable List<MallBean.KtProductListBean> data) {
        super(R.layout.item_main_center, data);
//        addData(new MallBean.KtProductListBean("凯通智造智能随行杯"));
////        addData(new MallBean.KtProductListBean("1分钟快速抚平衣服"));
////        addData(new MallBean.KtProductListBean("东北香大米2019新米"));
////        addData(new MallBean.KtProductListBean("东北香大米2019新米"));
////        addData(new MallBean.KtProductListBean("东北香大米2019新米"));
    }

    @Override
    protected void convert(BaseViewHolder helper, MallBean.KtProductListBean item) {
        helper.setText(R.id.tv_goods_name, String.valueOf(item.getTradename()));

        String price = "";
        if (!TextUtils.isEmpty(item.getPrice()) && Double.parseDouble(item.getPrice()) != 0.00) {
            price += item.getPrice();
            price += "KT";
        }
        if (!TextUtils.isEmpty(item.getMarket_price()) && Double.parseDouble(item.getMarket_price()) != 0.00) {
            if (!TextUtils.isEmpty(price)) {
                price += "+";
                price += item.getMarket_price();
                price += "消费积分";
            } else {
                price += item.getMarket_price();
                price += "消费积分";
            }
        }
        if (TextUtils.isEmpty(price)) {
            price = "0.00KT";
        }
        helper.setText(R.id.tv_goods_price, price);

        final ImageView ivGoodsBanner = helper.getView(R.id.iv_goods_banner);
        if (!TextUtils.isEmpty(item.getImg_zt())) {
            final String[] imgZtArr = item.getImg_zt().trim().split(",");
            GlideUtils.loadImg(mContext, ivGoodsBanner, imgZtArr[0]);
        } else {
            GlideUtils.loadImg(mContext, ivGoodsBanner, R.mipmap.icon_goods_banner);
        }
    }
}
